package org.management.base.data;

import lombok.Data;
import java.io.Serializable;

/**
 * @title: ResultData
 * @description: web数据返回集
 * @author: jiangyan
 * @date:  2019/1/27
 */
@Data
public class Result implements Serializable{

	/**
	 * 序列化id
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 状态码
	 */
	private Integer code;

	/**
	 * 返回状态信息
	 */
	private String message;

	/**
	 * 返回数据集
	 */
	private Object data;

	public static Result success(String message){
		return  getResultData(ResultCode.SUCCESS.getCode(), message, null);
	}

	public static Result success(Integer code, String message){
		return getResultData(code, message,null);
	}

	public static Result success(String message, Object data){
		return getResultData(ResultCode.SUCCESS.getCode(), message, data);
	}

	public static Result failure(String message){
		return getResultData(ResultCode.ERROR.getCode(), message, null);
	}

	public static Result failure(Integer code, String message){
		return getResultData(code, message, null);
	}

	private  static Result getResultData(Integer code, String message, Object data){
		Result result  = new Result();
		result.setCode(code);
		result.setMessage(message);
		if ( data != null ) {
			result.setData(data);
		}
		return result;
	}
}
